//
//  Button.m
//  EFExtend
//
//  Created by mac on 15/6/28.
//  Copyright (c) 2015年 Eric. All rights reserved.
//

#import "Button.h"


@interface Button ()

@end

@implementation Button{
    NSMutableArray *borads;
}

- (void)dealloc
{
   
    HM_SUPER_DEALLOC();
}

-(void)load{
    self.allowedLandscape = NO;
    self.allowedPortrait = YES;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.

    [self.customNavLeftBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [self.customNavLeftBtn setFrame:CGRectMakeBound(32, 32)];
    
    UIButten *_urlView = [[UIButten alloc]init];
    [self.view addSubview:_urlView];
    [_urlView setTitle:@"原文链接" forState:UIControlStateNormal];
    [_urlView setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    _urlView.titleLabel.font = [UIFont systemFontOfSize:14];
    _urlView.tag = 11111;
    [_urlView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_top).offset(0);
        make.right.mas_equalTo(self.view.mas_right).offset(-3);
//        make.width.mas_equalTo(100);
    }];

    
    borads = [[NSMutableArray alloc]init];
    
    [borads addObject:@{@"title":@"常规",@"type":@(UIButtenTypeNormal),@"txt":@"",@"img":@"http://t12.baidu.com/it/u=2627729012,2757221180&fm=32&s=6FF03AD45F22531708D914660300A074&w=800&h=533&img.JPEG",@"width":@"100"}];
    
    [borads addObject:@{@"title":@"常规",@"type":@(UIButtenTypeNormal),@"txt":@"注册",@"img":@"http://202.100.180.21/api.do?getimg&id=6653",@"width":@"100"}];
    
    [borads addObject:@{@"title":@"不规则点击",@"type":@(UIButtenTypeShaped),@"txt":@"",@"img":@"back.png"}];
    
    [borads addObject:@{@"title":@"左复选框",@"type":@(UIButtenTypeCheckBox|UIButtenTypeIconSideLeft),@"txt":@"复选框",@"img":@"checkbox.png"}];
    [borads addObject:@{@"title":@"点击图片复选框",@"type":@(UIButtenTypeCheckBox|UIButtenTypeIconClickedInside|UIButtenTypeIconSideLeft),@"txt":@"复选框",@"img":@"checkbox.png"}];
    [borads addObject:@{@"title":@"右复选框",@"type":@(UIButtenTypeCheckBox|UIButtenTypeIconSideRight),@"txt":@"复选框",@"img":@"checkbox.png"}];
    
    [borads addObject:@{@"title":@"Icon",@"type":@(UIButtenTypeIconSideTop),@"txt":@"上图标",@"img":@"checkbox_select.png"}];
    [borads addObject:@{@"title":@"Icon",@"type":@(UIButtenTypeIconSideBottom),@"txt":@"下图标",@"img":@"checkbox_select.png"}];
    [borads addObject:@{@"title":@"Icon",@"type":@(UIButtenTypeIconSideLeft),@"txt":@"左图标",@"img":@"checkbox_select.png"}];
    
    
    [self.tableView reloadData];
    [self.view sendSubviewToBack:self.tableView];
    
    UIButten * btn2 =  (UIButten*)[self.view viewWithTag:50];
//    btn2.style__ = [HMUIShapeStyle styleWithShape:[HMUIRoundedRectangleShape shapeWithRadius:5] next:[HMUISolidFillStyle styleWithColor:RGB(0, 187, 229) next:[HMUIInsetStyle styleWithInset:UIEdgeInsetsAll(10) next:nil]]];
//    [btn2 setTitle:@"抢单" forState:UIControlStateNormal];
//    [btn2 setBackgroundImagePrefixName:@"btn.png" title:@"抢单"];
    [btn2 setTitle:@"抢单" forState:UIControlStateNormal];
    [btn2 setBackgroundImage:[[UIImage imageNamed:@"btn_up"] stretched] forState:UIControlStateNormal];
//    btn2.backgroundImageEdgeInsets = UIEdgeInsetsAll(10);
//    [btn2 setTitleFont:[UIFont systemFontOfSize:15] forState:UIControlStateNormal];
    [btn2 sizeToFit];
    
    
    
    [[self.view viewWithTag:100] EFImage:[UIImage imageNamed:@"checkbox_select.png"]];
    UIButten * btn =  (UIButten*)[self.view viewWithTag:100];
    
    btn.titleEdgeInsets = UIEdgeInsetsContainsCenterTopLeft(btn.bounds, CGSizeMake(100, 20), 5, 5);
    btn.titleLabel.textAlignment = NSTextAlignmentLeft;
    btn.imageEdgeInsets = UIEdgeInsetsContainsCenter(btn.bounds, CGSizeMake(40, 40));
    
    btn = (UIButten*)[self.view viewWithTag:20];
    btn.style__ = [HMUIShapeStyle styleWithShape:[HMUIRoundedRectangleShape shapeWithRadius:5] next:[HMUISolidFillStyle styleWithColor:RGB(248, 128, 55) next:nil]];//[HMUISolidFillStyle styleWithColor:RGB(248, 128, 55) next:nil];
    [btn setImage:[UIImage imageNamed:@"img_gjhf"] forState:UIControlStateNormal];
    btn.tagString = @"Main.TGCarTraceBoard";
    
    
    UIView *footer = [UIView view] ;
    self.tableView.tableFooterView = [[footer EFFrame:CGRectMake(0, 0, self.view.width, 130)] EFBackgroundColor:[UIColor clearColor]];
    
    btn  = [UIView viewAsButten];
    btn.buttenType = UIButtenTypeCheckBox;
    btn.tagString = @"remember";
    btn.textMargin = 3;
    [[[[btn EFOwner:footer] EFTextColor:[UIColor blackColor]] EFText:@"记住密码"] EFImage:@"checkbox_select.png"] ;
    [btn EFTextHightLightColor:[UIColor redColor]];
    [btn setTitleFont:[UIFont systemFontOfSize:19.f] forState:UIControlStateSelected];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(footer.mas_top).offset(0);
        make.left.mas_equalTo(footer.mas_left).offset(15);
        make.height.mas_equalTo(60);
    }];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
//    [self backAndRemoveWithAnimate:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

ON_Button(signal){
    UIButten *btn = signal.source;
    if (btn.tag==111) {
        
    }
    if ([signal is:[UIButten TOUCH_UP_INSIDE]]) {
        if ([btn is:@"leftBtn"]) {//customNavLeftBtn
            [self backAndRemoveWithAnimate:YES];
        }else if ([btn is:@"rightBtn"]){//customNavRightBtn
            
        }
    }
}


#pragma  mark - table delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return borads.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier=@"listCell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (!cell) {
        cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        
    }
    
    NSDictionary *dic = [borads safeObjectAtIndex:indexPath.row];
    cell.textLabel.text = [dic valueForKey:@"title"];
    cell.backgroundColor = [UIColor md_grey_100];
    UIButten *btn = nil;//(id)cell.accessoryView;
    if (btn==nil) {
        btn = [UIButten spawn];
        cell.accessoryView = btn;
    }
    NSString *img = [dic valueForKey:@"img"];
        NSString *txt = [dic valueForKey:@"txt"];
        NSNumber *type = [dic valueForKey:@"type"];
    NSString *width = [dic valueForKey:@"width"];
    
    btn.buttenType = (UIButtenType)[type unsignedIntegerValue];
    [btn setImagePrefixName:img title:txt];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn.style__ = [HMUIShapeStyle styleWithShape:[HMUIRoundedRectangleShape shapeWithRadius:5] next:[HMUISolidFillStyle styleWithColor:RGB(255, 101, 121) next:[HMUIInsetStyle styleWithInset:UIEdgeInsetsAll(5) next:nil]]];
    
    if (width) {
        btn.frame = CGRectMake(0, 0, [width floatValue], 40);

    }else{
        btn.imageSize = CGSizeMake(22, 22);
//        [btn setTitleFont:[UIFont systemFontOfSize:18.f] forState:UIControlStateNormal];
//        btn.style__ = [HMUIShapeStyle styleWithShape:[HMUIRoundedRectangleShape shapeWithRadius:5] next:[HMUISolidFillStyle styleWithColor:RGB(255, 101, 121) next:nil]];
        [btn sizeToFit];
//        btn.size = CGSizeMake(100, 60);
    }
    
   
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

@end
